package com.common.po;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * <字母检索数据提供类>
 * <功能详细描述>
 * 
 * @author  huanglz
 * @version  [版本号, 2011-12-6]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class Character {
	
   /**
    *  快速字母检索：<a href="javascript:searchByCharacter('A')">A</a>&nbsp;
									
	   WHERE ( CONV(HEX(left(CONVERT(B.userName USING gbk),1)),16,10) between ?startNumber(例：'45217') and ?endNumber(例：'45252') 
	   or B.username like ?characterName(例：'A%') or B.username like ?LowerCharacterName(例：'a%') )
	   // 对字母V、U、I进行特殊处理，汉字拼音首字母中没有V、U、I三者
	   WHERE B.username like ?characterName(例：'V%') or B.username like ?LowerCharacterName(例：'v%')
   */
	
	Map<String,String> map=new HashMap<String, String>();
	
	private static Character instance = null;
	
	private Character () {
		initData();
	}
	
	public static Character getInstance() {
		if(instance == null) {
			instance = new Character();
		}
		return instance;
	}
	
	/**
	 * <数据对应关系>
	 * <功能详细描述> [参数说明]
	 * 
	 * @return void [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	private void initData(){
		map.put("A", "45217,45252");
		map.put("B", "45253,45760");
		map.put("C", "45761,46317");
		map.put("D", "46318,46825");
		map.put("E", "46826,47009");
		map.put("F", "47010,47296");
		map.put("G", "47297,47613");
		map.put("H", "47614,48118");
		map.put("J", "48119,49061");
		map.put("K", "49062,49323");
		map.put("L", "49324,49895");
		map.put("M", "49896,50370");
		map.put("N", "50371,50613");
		map.put("O", "50614,50621");
		map.put("P", "50622,50905");
		map.put("Q", "50906,51386");
		map.put("R", "51387,51445");
		map.put("S", "51446,52217");
		map.put("T", "52218,52697");
		map.put("W", "52698,52979");
		map.put("X", "52980,53688");
		map.put("Y", "53689,54480");
		map.put("Z", "54481,55289");
		
	}
	/**
	 * <获取字母范围开始值>
	 * <功能详细描述>
	 * @param character
	 * @return [参数说明]
	 * 
	 * @return String [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	 public String getStartKey(String character){
		 if(null!=map.get(character)){
			String key=String.valueOf(map.get(character));
			String [] allKey=key.split(",");
			return String.valueOf(allKey[0]);
		 }else{
			 return "";
		 }
	 }
	 
	 /**
	  * <获取字母范围结束值>
	  * <功能详细描述>
	  * @param character
	  * @return [参数说明]
	  * 
	  * @return String [返回类型说明]
	  * @exception throws [违例类型] [违例说明]
	  * @see [类、类#方法、类#成员]
	  */
	 public String getEndKey(String character){
		 if(null!=map.get(character)){
			String key=String.valueOf(map.get(character));
			String [] allKey=key.split(",");
			return String.valueOf(allKey[1]);
		 }else{
			 return "";
		 }
	 }
	 
	 // 调试
	 public static void main(String[] args)
	 {
//		 if("character".equals(flag)){//进行字母检索
//	        	String startNumber="";//字母范围开始值
//	        	String endNumber="";//字母范围结束值									     
//	        	String characterName=StringTool.getNotNullStrValue(dictionary.getString("characterName"));//得到需要检索的字母
//	        	//对字母V、U、I进行特殊处理
//	        	if(!"I".equals(characterName) && !"V".equals(characterName) && !"U".equals(characterName)){
//	        		startNumber=Character.getInstance().getStartKey(characterName);
//	        		endNumber=Character.getInstance().getEndKey(characterName);
//	        		sqlDataSource.setParameter("startNumber", startNumber);
//	        		sqlDataSource.setParameter("endNumber", endNumber);
//	            	flag="searchCharacter";
//	        	}
//	        	sqlDataSource.setParameter("characterName", characterName+"%");
//	        	sqlDataSource.setParameter("LowerCharacterName", characterName.toLowerCase()+"%");
//	        }
	 }
}
